package core.io;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.IOException;
import java.io.InputStream;

/**
 * 把信息进行封装：socket -> Reuqets
 * @author wsz
 * @date 2021/11/12 17:27
 **/
@Data
@NoArgsConstructor
public class Request {
    private String appBase;
    private String method;
    private String url;
    private InputStream inputStream;

    public Request(InputStream inputStream) throws IOException {
        this(inputStream, "webapps");
    }

    public Request(InputStream inputStream, String appBase) throws IOException {
        this.inputStream = inputStream;
        int count = 0;
        while (count == 0) {
            count = inputStream.available();
        }
        byte[] bytes = new byte[count];
        inputStream.read(bytes);

        String inputStr = new String(bytes);
        String firstLine = inputStr.split("\\n")[0];
        String[] strings = firstLine.split(" ");
        this.method = strings[0];
        this.url = strings[1];
        this.appBase = appBase;
    }

}
